//
//  HMTabBarViewController.swift
//  Weibo
//
//  Created by 李学林 on 15/12/5.
//  Copyright © 2015年 tete. All rights reserved.
//

import UIKit
import SVProgressHUD
class HMTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = HMTabBar()
        
        tabBar.composeButtonClosure = { [weak self] in
           // 中间加号按钮被点击了
            
            if !HMWBUserInfoViewModel.sharedAccount.userLogin{
                SVProgressHUD.showErrorWithStatus("请先登录")
                return
            }
            
            // 初始化 composeView
            let composeView = HMComposeView()
            composeView.show(self)
            
        }
        
        
        
        setValue(tabBar, forKey: "tabBar")
        
//        self.tabBar = tabBar
        
        addChildViewController(HMHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(HMMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(HMDiscoveryViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(HMProfileViewController(), imageName: "tabbar_profile", title: "我")

    }

    // 添加自控制器
     func addChildViewController(childController: UIViewController , imageName:String , title:String) {
        // 设置控制器的tabbarItem属性为自定义的
        
        childController.tabBarItem = HMTabBarItem()
        
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.title = title;
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        addChildViewController(HMNavgationViewController(rootViewController: childController))
        
    }
    

    
}
